<!-- 在线报名 -->
<template>
  <div>
    <van-nav-bar
      :z-index="999"
      :fixed="true"
      left-arrow
      @click-left="onClickLeft"
      :placeholder="true"
      title="在线报名"
    ></van-nav-bar>

    <!-- 报名内容 -->
    <div class="apply-online">
      <!-- 上传头像 -->
      <!-- <van-uploader :max-count="1" :deletable="false" spreview-image v-model="fileList">
        <van-button icon="plus" type="primary">上传头像</van-button>
      </van-uploader>-->

      <!-- 是否是本地 -->
      <div class="standFor">
        <div>驾驶人来源</div>
        <van-radio-group
          @change="choose"
          direction="horizontal"
          icon-size="14px"
          v-model="radio"
        >
          <van-radio name="1">本地</van-radio>
          <van-radio name="2">外地</van-radio>
        </van-radio-group>
      </div>

      <!-- 申请类型 -->
      <!-- <van-cell-group>
        <van-field
          @click="Application()"
          v-model="type1"
          placeholder="请选择申请类型"
          disabled
        >
          <template #label>
            <div>申请类型</div>
            <img
              class="requiredFields"
              src="../../assets/images/bitian.png"
              alt
            />
          </template>
        </van-field>
      </van-cell-group> -->
      <!-- 申请类型弹出层 -->
      <!-- <van-popup
        v-model="ApplicationType"
        position="bottom"
        round
        :style="{ height: '30%' }"
      >
        <div class="application-type">
          <div>申请类型</div>
          <div
            v-for="(item, index) in TypeList"
            :key="index"
            @click="ClickType(item.value)"
          >
            {{ item.title }}
          </div>
        </div>
      </van-popup> -->
      <div class="ce_basic">
        <img class="requiredFields" src="../../assets/images/bitian.png" alt />
        <p>申请类型</p>
        <select v-model="type" class="ce_type">
          <option value="1">初次申请</option>
          <option value="2">增驾</option>
        </select>
      </div>

      <!-- 现有驾照 -->
      <!-- <van-cell-group>
        <van-field
          @click="NewDrivingLicense()"
          v-model="drivingLicence"
          placeholder="请选择现有驾照"
          disabled
        >
          <template #label>
            <div>现有驾照</div>
          </template>
        </van-field>
      </van-cell-group> -->
      <!-- 现有驾照弹出层 -->
      <!-- <van-popup
        v-model="NewDriving"
        position="bottom"
        round
        :style="{ height: '30%' }"
      >
        <div class="application-type">
          <div>现有驾照</div>
          <div
            v-for="(item, index) in NewList"
            :key="index"
            @click="ClickDriving(item)"
          >
            {{ item }}
          </div>
        </div>
      </van-popup> -->
      <div class="ce_basic">
        <p>现有驾照</p>
        <select v-model="drivingLicence" class="ce_type">
          <option value="">请选择</option>
          <option value="A1">A1</option>
          <option value="A2">A2</option>
          <option value="A3">A3</option>
          <option value="B1">B1</option>
          <option value="B2">B2</option>
          <option value="C1">C1</option>
          <option value="C2">C2</option>
          <option value="C3">C3</option>
          <option value="C4">C4</option>
          <option value="D">D</option>
          <option value="E">E</option>
          <option value="F">F</option>
          <option value="M">M</option>
          <option value="N">N</option>
          <option value="P">P</option>
        </select>
      </div>
      <!-- end -->

      <!-- 选择驾校 -->
      <div class="ce_basic">
        <p>选择驾校</p>
        <img class="requiredFields" src="../../assets/images/bitian.png" alt />
        <select v-model="ChooseSt" class="ce_type" @blur="drivingTest">
          <option
            class="select_option"
            v-for="(item, index) in drivingSchool"
            :key="index"
            :value="item.id"
            >{{ item.name }}</option
          >
        </select>
      </div>
      <!-- end -->

      <!-- 选择教练 -->
      <div class="ce_basic">
        <p>选择教练</p>
        <!--  @blur="cardFocus" -->
        <select v-model="coach" class="ce_type">
          <option value="">请选择</option>
          <option
            v-for="(item, index) in trainerList"
            :key="index"
            :value="item.code"
            >{{ item.name }}</option
          >
        </select>
      </div>
      <!-- end -->

      <!-- 准驾车型 -->
      <div class="ce_basic">
        <p>准驾车型</p>
        <img class="requiredFields" src="../../assets/images/bitian.png" alt />
        <select @blur="gradeType" v-model="override" class="ce_type">
          <option
            v-for="(item, index) in examLicense"
            :key="index"
            :value="item"
            >{{ item }}</option
          >
        </select>
      </div>
      <!-- end -->

      <!-- 班型 -->
      <div class="ce_basic">
        <p>班型</p>
        <img class="requiredFields" src="../../assets/images/bitian.png" alt />
        <select v-model="banks" class="ce_type">
          <option
            v-for="(item, index) in banksList"
            :key="index"
            :value="item.id"
            >{{ item.stageName }}</option
          >
        </select>
      </div>
      <!-- end -->

      <!-- 姓名 -->
      <van-cell-group>
        <van-field v-model="text" placeholder="请输入姓名">
          <template #label>
            <div>姓名</div>
            <img
              class="requiredFields"
              src="../../assets/images/bitian.png"
              alt
            />
          </template>
        </van-field>
      </van-cell-group>
      <!-- end -->

      <!-- 国籍 -->
      <div class="ce_basic">
        <p>国籍</p>
        <img class="requiredFields" src="../../assets/images/bitian.png" alt />
        <select v-model="nationality" class="ce_type">
          <option
            v-for="(item, index) in nationalitys"
            :key="index"
            :value="item.dictValue"
            >{{ item.remarks }}</option
          >
        </select>
      </div>
      <!-- <van-cell-group>
        <van-field v-model="nationality" placeholder="请输入国籍">
          <template #label>
            <div>国籍</div>
            <img class="requiredFields" src="../../assets/images/bitian.png" alt />
          </template>
        </van-field>
      </van-cell-group>-->
      <!-- end -->

      <!-- 证件类型 -->
      <div class="ce_basic">
        <p>证件类型</p>
        <img class="requiredFields" src="../../assets/images/bitian.png" alt />
        <select @blur="papers" v-model="papersType" class="ce_type">
          <option value="1">身份证</option>
          <option value="2">护照</option>
          <option value="3">港澳台身份证</option>
          <option value="4">军官证</option>
        </select>
      </div>
      <!-- end -->

      <!-- 证件号码 -->
      <van-cell-group>
        <van-field
          @blur="shiftOut"
          v-model="IDCard"
          placeholder="请输入证件号码"
        >
          <template #label>
            <div>证件号码</div>
            <img
              class="requiredFields"
              src="../../assets/images/bitian.png"
              alt
            />
          </template>
        </van-field>
      </van-cell-group>
      <!-- end -->

      <!-- 性别 -->
      <div class="ce_basic">
        <p>性别</p>
        <img class="requiredFields" src="../../assets/images/bitian.png" alt />
        <select v-model="set" :disabled="forbid" readonly class="ce_type">
          <option value="0">男</option>
          <option value="1">女</option>
        </select>
      </div>
      <!-- end -->

      <!-- 出生年月 -->
      <!-- @click="showData" -->

      <van-cell v-if="!forbid" is-link @click="showData">
        <template #title>
          <div class="title-census">
            <p>出生年月</p>
            <div>{{ years }}</div>
            <img
              class="requiredFields"
              src="../../assets/images/bitian.png"
              alt
            />
          </div>
        </template>
      </van-cell>
      <van-cell v-else is-link>
        <template #title>
          <div class="title-census">
            <p>出生年月</p>
            <div>{{ years }}</div>
            <img
              class="requiredFields"
              src="../../assets/images/bitian.png"
              alt
            />
          </div>
        </template>
      </van-cell>
      <van-popup
        v-model="show"
        round
        position="bottom"
        :style="{ height: '40%' }"
      >
        <van-datetime-picker
          type="date"
          :min-date="minDate"
          :max-date="maxDate"
          @cancel="CallOff"
          @confirm="ascertain"
          v-model="currentDate"
        />
      </van-popup>

      <!-- <van-cell is-link @click="showPopup">展示弹出层</van-cell> -->
      <!-- end -->

      <!-- 年龄 -->
      <!-- <van-cell-group>
        <van-field v-model="age" label="年龄" placeholder="请输入年龄" />
      </van-cell-group>-->
      <!-- end -->

      <!-- 身份证地址 -->
      <van-cell-group>
        <van-field v-model="site" placeholder="请输入身份证地址：省、市、区/镇">
          <template #label>
            <div>身份证地址</div>
            <img
              class="requiredFields"
              src="../../assets/images/bitian.png"
              alt
            />
          </template>
        </van-field>
      </van-cell-group>
      <!-- end -->

      <!-- 居住地 -->
      <!-- @click="showPopup" -->
      <van-cell-group>
        <van-field
          v-model="building"
          placeholder="请输入身份证地址：省、市、区/镇"
        >
          <template #label>
            <div>居住地</div>
            <img
              class="requiredFields"
              src="../../assets/images/bitian.png"
              alt
            />
          </template>
        </van-field>
      </van-cell-group>

      <!-- <van-cell is-link @click="placeAbode">
        <template #title>
          <div class="title-census">
            <p>居住地</p>
            <div>{{building}}</div>
          </div>
        </template>
      </van-cell>

      <van-popup v-model="residential" round position="bottom" :style="{ height: '40%' }">
        <van-area :columns-num="2" />
      </van-popup>
      end-->

      <!-- 居住证号 -->
      <van-cell-group v-if="standFor">
        <van-field
          v-model="residencePermit"
          type="digit"
          label="居住证号"
          placeholder="请输入居住证号"
        />
      </van-cell-group>

      <!-- 是外来人员时显示 -->
      <div v-else>
        <van-cell-group>
          <van-field v-model="residencePermit" placeholder="请输入居住证号">
            <template #label>
              <div>居住证号</div>
              <img
                class="requiredFields"
                src="../../assets/images/bitian.png"
                alt
              />
            </template>
          </van-field>
        </van-cell-group>
      </div>

      <!-- end -->

      <!-- 居住证签发时间 -->
      <div v-if="standFor">
        <van-cell is-link @click="cardSigner">
          <template #title>
            <div class="title-census">
              <p>居住证签发时间</p>
              <div>{{ cardTime }}</div>
            </div>
          </template>
        </van-cell>

        <van-popup
          v-model="signer"
          round
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-datetime-picker
            v-model="issuingAuthority"
            type="date"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="residence"
            @confirm="residenceTime"
          />
        </van-popup>
      </div>

      <!-- 外来人员 -->
      <div v-else>
        <van-cell is-link @click="cardSigner">
          <template #title>
            <div class="title-census">
              <p>居住证签发时间</p>
              <div>{{ cardTime }}</div>
              <img
                class="requiredFields"
                src="../../assets/images/bitian.png"
                alt
              />
            </div>
          </template>
        </van-cell>

        <van-popup
          v-model="signer"
          round
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-datetime-picker
            v-model="issuingAuthority"
            type="date"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="residence"
            @confirm="residenceTime"
          />
        </van-popup>
      </div>
      <!-- end -->

      <!-- 暂住证 -->
      <!-- @click="showData" -->
      <div v-if="standFor">
        <van-cell is-link @click="uptown">
          <template #title>
            <div class="title-census">
              <p>暂住证到期时间</p>
              <div>{{ stayExpire }}</div>
            </div>
          </template>
        </van-cell>

        <van-popup
          v-model="residentialTome"
          round
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-datetime-picker
            type="date"
            v-model="dataccc"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="temporary"
            @confirm="temporaryTime"
          />
        </van-popup>
      </div>

      <div v-else>
        <van-cell is-link @click="uptown">
          <template #title>
            <div class="title-census">
              <p>暂住证到期时间</p>
              <div>{{ stayExpire }}</div>
              <img
                class="requiredFields"
                src="../../assets/images/bitian.png"
                alt
              />
            </div>
          </template>
        </van-cell>

        <van-popup
          v-model="residentialTome"
          round
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-datetime-picker
            type="date"
            v-model="dataccc"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="temporary"
            @confirm="temporaryTime"
          />
        </van-popup>
      </div>
      <!-- end -->

      <!-- 招生来源 -->
      <div class="ce_basic">
        <p>招生来源</p>
        <select v-model="source" class="ce_type">
          <option value="1">自主报名</option>
          <option value="3">老学员介绍</option>
          <option value="4">宣传彩页</option>
          <option value="5">代理</option>
          <option value="6">电视广告</option>
          <option value="7">公交广告</option>
          <option value="8">网络推广</option>
          <option value="9">其它</option>
        </select>
      </div>
      <!-- end -->

      <!-- 介绍人 sponsors -->
      <div class="ce_basic">
        <p>介绍人</p>
        <select v-model="sponsor" class="ce_type">
          <option
            v-for="(item, index) in sponsors"
            :key="index"
            :value="item.id"
            >{{ item.name }}</option
          >
        </select>
      </div>
      <!-- end -->

      <!-- 预选教练 -->
      <!-- <div class="ce_basic">
        <p>预选教练</p>
        <select v-model="primary" class="ce_type">
          <option value="李大钊">李大钊</option>
          <option value="韩梅梅">韩梅梅</option>
        </select>
      </div>-->
      <!-- end -->

      <!-- 备注 -->
      <van-field
        v-model="message"
        rows="1"
        autosize
        label="备注"
        type="textarea"
        placeholder="请输入备注"
      />
      <!-- end -->

      <!-- 友情提示 -->
      <div class="friendly-reminder">
        友情提示:如果缴费前修改报名信息去个人中心里面订单里面修改
      </div>

      <div @click="IfConsent" class="ao-deal">
        <img v-if="condition" src="../../assets/images/67.png" alt />
        <img v-else src="../../assets/images/68.png" alt />
        <div>
          我已阅读并同意
          <span @click="contrsct">云驾校合同</span>
        </div>
      </div>

      <!-- 报名按钮 -->
      <div class="ao_button" @click="payment">报名</div>
      <!-- end -->
    </div>

    <!-- 弹出层 -->
    <!-- <van-cell is-link>展示弹出层</van-cell> -->
    <van-popup @click-overlay="padlock" class="popups-popping" v-model="popups">
      <div class="ao-message">
        <div class="personal-details">个人信息</div>
        <div>
          <div>
            <p>姓名：</p>
            <div>{{ text }}</div>
          </div>
          <div>
            <p>性别：</p>
            <div>{{ set == "0" ? "男" : "女" }}</div>
          </div>
          <div>
            <p v-if="papersType == '1'">身份证：</p>
            <p v-else-if="papersType == '2'">护照：</p>
            <p v-else-if="papersType == '3'">港澳台身份证：</p>
            <p v-else-if="papersType == '4'">军官证：</p>
            <div>{{ IDCard }}</div>
          </div>
          <div>
            <p>手机号：</p>
            <div>{{ phone }}</div>
          </div>
        </div>

        <div class="personal-details">驾校信息</div>
        <div>
          <div>
            <p>驾校名称：</p>
            <div>{{ SchoolName }}</div>
          </div>
          <div>
            <p>准驾车型：</p>
            <div>{{ cardType }}</div>
          </div>
          <div>
            <p>班型：</p>
            <div>{{ Banks }}</div>
          </div>
          <div>
            <p>教练：</p>
            <div>{{ CoardName }}</div>
          </div>
        </div>
      </div>

      <div class="popping">
        <div>费用名称</div>
        <div>学时单价</div>
        <div>学时数量</div>
        <div>金额</div>
      </div>

      <div class="popping" v-for="(item, index) in costBreakdown" :key="index">
        <div>{{ item.stageName }}</div>
        <div v-if="item.classPrice == '0'" class="popping-detail">-</div>
        <div v-else class="popping-detail">{{ item.classPrice }}</div>
        <div v-if="item.classNum == '0'" class="popping-detail">-</div>
        <div v-else class="popping-detail">{{ item.classNum }}</div>
        <div v-if="item.priceAll == '0'" class="popping-detail">-</div>
        <div v-else class="popping-detail">{{ item.priceAll }}</div>
      </div>
      <div class="hourTotal">
        <div>总计</div>
        <div>{{ summations }}</div>
      </div>

      <!-- 按钮 -->
      <div class="button-pay">
        <div @click="abrogate">取消</div>
        <div @click="determine">确认</div>
      </div>
    </van-popup>
  </div>
</template>

<script>
// 引入vant
import { Dialog } from "vant";
import { Toast } from "vant";
// import { Area } from "vant";
import {
  nativePlace, // 籍贯
  applyOnline, // 提交
  particulars, // 在线报名明细
  drivingSchool, // 驾校列表
  opticalService, // 驾照类型
  instructor, // 教练
  // vehicleModel,
  cordList, // 教练列表
  DetailsBanks, // 班型
  Introducer // 介绍人
} from "../../assets/js/api/apply.js";
// payment
import { SettingUp } from "../../assets/js/api/user.js";
export default {
  name: "ApplyOnline",
  data() {
    return {
      radio: "1", // 是否是本地户口
      fileList: [], //上传头像
      // profilePhoto: "",
      type: "", //申请类型
      override: "", //准驾车型
      banks: "", // 班型
      AllBanks: [], // 全部班型
      banksList: [], // 班型列表
      drivingLicence: "", // 现有驾照
      ChooseSt: "", //选择驾校
      coach: "", //选择教练
      text: "", // 姓名
      nationality: "1", //国籍
      papersType: "1", //证件类型
      IDCard: "", //证件号码
      set: "", // 性别
      show: false,
      Datamax: new Date(),
      forbid: true, // 如果用户选择身份证，则是自动填入的
      years: "", //出生年月日
      //dataTome: "", //出生日期
      // age: "", // 年龄
      site: "", //地址
      residencePermit: "", //居住证号
      sponsor: "", // 介绍人
      source: "", //招生来源
      primary: "", // 预选教练
      message: "", // 备注
      building: "", //  居住地
      residential: false, //居住地选择
      standFor: true, //按照是否是外来人员选择
      // 户籍地联动
      // census: false,
      // 出生日期
      minDate: new Date(1950, 1, 1),
      maxDate: new Date(2120, 12, 30),
      dataccc: new Date(),
      // currentDate: "",
      currentDate: new Date(),
      signer: false, //居住证日期是否显示
      issuingAuthority: new Date(),
      cardTime: "", // 居住证签打时间
      residentialTome: false, //暂住证
      stayExpire: "", //暂住证到期
      // signUp: false, // 报名时间
      // signUpTime: "", //报名时间

      popups: false, //弹出层

      costBreakdown: [], //费用明细
      summations: 0, // 费用总和

      //  一下数据绑定
      dataDirthday: "", //出生日期 年-月-日，假数据，无意义
      nationalitys: [], //国籍

      // 驾校
      drivingSchool: [],
      trainerList: [], // 教练列表

      examLicense: [], // 驾照类型
      issuingTime: "",
      sponsors: [], // 介绍人下拉框
      condition: true, // 是否同意协议
      phone: "", // 用户电话
      // 班型明细
      SchoolName: "", //驾校名字
      cardType: "", //车型
      Banks: "", // 班型
      CoardName: "", // 教练名字

      // 管理申请类型是否弹出
      ApplicationType: false,
      type1: "",
      TypeList: [
        {
          title: "初次申请",
          value: "1"
        },
        { title: "增加", value: "2" }
      ],

      // 现有驾照，管理现有驾照 是否弹出
      NewDriving: false,
      NewList: [
        "A1",
        "A2",
        "A3",
        "B1",
        "B2",
        "C1",
        "C2",
        "C3",
        "C4",
        "D",
        "E",
        "F",
        "M",
        "N",
        "P"
      ]
    };
  },

  created() {
    let dsBridge = require("dsbridge");
    dsBridge.call("goBack", "", function() {
      history.go(-1);
    });
    // console.log(this.$route.params.lid);

    SettingUp().then(res => {
      this.phone = res.data.phonenumber;
      // console.log(res.data.phonenumber);
    });

    // 驾校列表
    drivingSchool().then(res => {
      // console.log(res.data);
      this.drivingSchool = res.data;
      this.ChooseSt = this.$route.params.lid;
      // 教练列表
      // console.log(this.ChooseSt);
      instructor(this.ChooseSt).then(res => {
        this.trainerList = res.data;
        // console.log(this.trainerList);
      });
      DetailsBanks(this.ChooseSt).then(res => {
        // console.log(res);
        this.AllBanks = res.data;
      });
    });

    //驾照类型列表
    opticalService(this.$route.params.lid).then(res => {
      this.examLicense = res.data;
      // console.log(this.examLicense);
    });

    // 教练列表

    cordList(this.$route.params.id).then(res => {
      // console.log(res.data);
      // console.log(this.$route.params.id);
      let array = res.data;
      // console.log(array[1].id);
      // console.log(array[0].code);
      this.ChooseSt = array[1].id;
      this.coach = array[0].code;
    });

    // 国籍接口
    nativePlace().then(res => {
      // console.log(res);
      this.nationalitys = res.data;
      // console.log(this.nationalitys);
    });

    // 介绍人

    Introducer(this.$route.params.lid).then(res => {
      // console.log(res);
      if (res.code == 0) {
        this.sponsors = res.data;
      }
    });
  },

  methods: {
    // 现有驾照
    NewDrivingLicense() {
      this.NewDriving = true;
    },
    ClickDriving(item) {
      this.drivingLicence = item;
      this.NewDriving = false;
    },

    Application() {
      this.ApplicationType = true;
      // console.log("申请类型");
    },
    ClickType(value) {
      if (value == "1") {
        this.type1 = "初次申请";
      } else {
        this.type1 = "增加";
      }
      this.type = value;
      // console.log(this.type);
      this.ApplicationType = false;
    },

    //
    gradeType() {
      // console.log(this.override);
      if (this.override == "A1") {
        if (this.type == "1") {
          this.type = "2";
          Toast("A1驾照只能是增驾");
        }
      }
      this.banksList = [];
      // console.log(this.override);
      // AllBanks(this.ChooseSt, this.override).then(res => {
      //   this.banksList = res.data;
      // });
      for (let i = 0; i < this.AllBanks.length; i++) {
        if (this.override == this.AllBanks[i].stageType) {
          this.banksList.push(this.AllBanks[i]);
        }
      }
      // console.log(this.banksList);
    },

    // 当选择驾校之后触发的函数
    drivingTest() {
      /**
       * 当再次选择驾校的时候，能清空对应的教练，车型，班型介绍人。以及对应的列表
       */
      this.coach = "";
      this.override = "";
      this.banks = "";
      this.sponsor = "";
      this.trainerList = [];
      this.sponsors = [];
      this.banksList = [];
      this.examLicense = [];
      instructor(this.ChooseSt).then(res => {
        // console.log(res);
        this.trainerList = res.data;
        // console.log(this.trainerList);
      });
      // 当重新选择教练的时候，重新加载教练，车型，班型，介绍人
      // console.log(this.ChooseSt);
      DetailsBanks(this.ChooseSt).then(res => {
        // console.log(res);
        this.AllBanks = res.data;
      });
      opticalService(this.ChooseSt).then(res => {
        // console.log(this.ChooseSt);
        // console.log(res);
        this.examLicense = res.data;
        // console.log(this.examLicense);
      });
      // vehicleModel(this.coach).then(res => {
      //   // 如果选择教练先让驾照类型为空

      //   this.examLicense = res.data;
      //   console.log(res);
      // });

      Introducer(this.ChooseSt).then(res => {
        // console.log(res);
        if (res.code == 0) {
          this.sponsors = res.data;
        }
      });
    },

    // 点击弹出框按确认执行

    // 支付跳转
    payment() {
      if (this.override == this.drivingLicence) {
        Toast.fail("准驾车型和现有驾照不能是一个类型");
        return;
      }
      if (this.condition) {
        Toast.fail("请先同意协议");
        return;
      }

      if (this.radio == "1") {
        // console.log("性别：" + this.set);
        if (this.type == "") {
          Toast("请选择申请类型");
          return;
        }
        if (this.ChooseSt == "") {
          Toast("请选择驾校");
          return;
        }
        if (this.override == "") {
          Toast("请选择准驾车型");
          return;
        }
        if (this.banks == "") {
          Toast("请选择班型");
          return;
        }
        if (this.text == "") {
          Toast("请输入姓名");
          return;
        }
        if (this.nationality == "") {
          Toast("请选择国籍");
          return;
        }
        if (this.papersType == "") {
          Toast("请选择证件类型");
          return;
        }
        if (this.IDCard == "") {
          Toast("请输入证件号码");
          return;
        }
        if (this.set === "") {
          Toast("请选择性别");
          return;
        }
        if (this.years == "") {
          Toast("请选择出生年月");
          return;
        }
        if (this.site == "") {
          Toast("请输入身份证地址");
          return;
        }
        if (this.building == "") {
          Toast("请输入居住地");
          return;
        }

        // if (
        //   this.type === "" ||
        //   this.site === "" ||
        //   this.override === "" ||
        //   this.ChooseSt === "" ||
        //   this.banks === "" ||
        //   this.text === "" ||
        //   this.nationality === "" ||
        //   this.IDCard === "" ||
        //   this.papersType === "" ||
        //   this.set === "" ||
        //   this.years === ""
        // ) {
        //   Dialog.alert({
        //     message: "请完善您信息"
        //     // theme: "round-button"
        //   }).then(() => {});
        //   return;
        //   // alert("请完善信息");
        // }

        particulars(this.banks).then(res => {
          console.log(res);
          this.costBreakdown = res.data;
          let number = 0;
          for (let i = 0; i < this.costBreakdown.length; i++) {
            number += this.costBreakdown[i].priceAll;
            // console.log(number);
          }
          this.summations = number;
          // console.log(this.summations);
        });
      }
      if (this.radio == "2") {
        if (this.type == "") {
          Toast("请选择申请类型");
          return;
        }
        if (this.ChooseSt == "") {
          Toast("请选择驾校");
          return;
        }
        if (this.override == "") {
          Toast("请选择准驾车型");
          return;
        }
        if (this.banks == "") {
          Toast("请选择班型");
          return;
        }
        if (this.text == "") {
          Toast("请输入姓名");
          return;
        }
        if (this.nationality == "") {
          Toast("请选择国籍");
          return;
        }
        if (this.papersType == "") {
          Toast("请选择证件类型");
          return;
        }
        if (this.IDCard == "") {
          Toast("请输入证件号码");
          return;
        }
        if (this.set === "") {
          Toast("请选择性别");
          return;
        }
        if (this.years == "") {
          Toast("请选择出生年月");
          return;
        }
        if (this.site == "") {
          Toast("请输入身份证地址");
          return;
        }
        if (this.building == "") {
          Toast("请输入居住地");
          return;
        }
        if (this.standFor === "") {
          Toast("请输入居住证号");
          return;
        }
        if (this.standFor === "") {
          Toast("请选择居住证签发时间");
          return;
        }
        if (this.stayExpire === "") {
          Toast("请选择暂住证到期时间");
          return;
        }

        // if (
        //   this.type === "" ||
        //   this.site === "" ||
        //   this.override === "" ||
        //   this.ChooseSt === "" ||
        //   this.banks === "" ||
        //   this.text === "" ||
        //   this.nationality === "" ||
        //   this.IDCard === "" ||
        //   this.papersType === "" ||
        //   this.set === "" ||
        //   this.years === "" ||
        //   this.site === "" ||
        //   this.building === "" ||
        //   this.residencePermit === "" ||
        //   this.cardTime === "" ||
        //   this.stayExpire === ""
        // ) {
        //   Dialog.alert({
        //     message: "请完善您信息"
        //     // theme: "round-button"
        //   }).then(() => {});
        //   return;
        //   // alert("请完善信息");
        // }

        particulars(this.banks).then(res => {
          this.costBreakdown = res.data;
          let number = 0;
          for (let i = 0; i < this.costBreakdown.length; i++) {
            number += this.costBreakdown[i].priceAll;
            // console.log(number);
          }
          this.summations = number;
          // console.log(this.summations);
        });
      }

      //  SchoolName cardType Banks CoardName
      // 班型明细->驾校名字
      for (let i = 0; i < this.drivingSchool.length; i++) {
        if (this.ChooseSt == this.drivingSchool[i].id) {
          this.SchoolName = this.drivingSchool[i].name;
          // console.log(this.drivingSchool[i]);
        }
      }
      // 班型明细->车型
      for (let i = 0; i < this.examLicense.length; i++) {
        // console.log(this.examLicense[i]);
        if (this.override == this.examLicense[i]) {
          this.cardType = this.examLicense[i];
        }
        // if (this.this.examLicense[i] == this.examLicense[i]) {
        //   this.cardType = this.examLicense[i];
        // }
      }
      // 班型明细->班型
      for (let i = 0; i < this.banksList.length; i++) {
        if (this.banks == this.banksList[i].id) {
          this.Banks = this.banksList[i].stageName;
        }
      }
      // 班型明细->教练
      for (let i = 0; i < this.trainerList.length; i++) {
        if (this.coach == this.trainerList[i].code) {
          this.CoardName = this.trainerList[i].name;
        }
      }

      this.popups = true;

      // 当不为空都验证通过之后，执行保存信息
    },

    determine() {
      let obj = {
        jsrly: this.radio,
        ywlx: this.type,
        bmcx: this.override,
        yjcx: this.drivingLicence,
        jgbh: this.ChooseSt, // 驾校id
        yxjl: this.coach, // 教练id
        bz: this.banks, // 班型
        name: this.text,
        nationality: this.nationality,
        cardtype: this.papersType,
        idcard: this.IDCard,
        sex: this.set,
        birth: this.years,
        idcardAddress: this.site,
        address: this.building,
        jzzcode: this.residencePermit,
        jzzqftime: this.cardTime,
        zzz: this.stayExpire,
        zsly: this.source,
        jsr: this.sponsor,
        remarks: this.message,
        birthday: this.years,
        createBy: this.ChooseSt
      };

      applyOnline(obj).then(res => {
        // console.log(res);
        if (res.code == 501) {
          Toast.fail("重复报名,请到个人中心查看订单");
          return;
        }

        if (res.code == 0) {
          this.popups = false;
          this.orderForm = res.msg;
          Dialog.confirm({
            message: `报名成功<br>是否去缴费`,
            confirmButtonText: "确认",
            cancelButtonText: "取消"
          })
            .then(() => {
              this.$router.push({ path: "/OnlinePayment" });
              // payment().then(res => {
              //   if (res.code == 0) {
              //     Toast.success("缴费成功");
              //     this.$router.go(0);
              //   }
              // });
            })
            .catch(() => {
              Toast("请在我的订单中查看");
            });
        }
      });
    },

    onClickLeft() {
      this.$router.go(-1);
    },

    // 是否外来人口
    choose() {
      // console.log(this.radio);
      if (this.radio == "1") {
        this.standFor = true;
      } else {
        this.standFor = false;
      }
    },

    // 点击取消按钮时
    abrogate() {
      this.popups = false;
    },

    // 关闭弹窗执行的
    padlock() {
      // console.log("关闭弹窗");
      this.summation = [];
    },

    // 当失去焦点时，验证证件号码
    shiftOut() {
      // 判断当前用户选择了那种证件，进行相应的验证
      // 1：身份证，2：护照，3：港澳台身份证，4：军官证...
      if (this.papersType == "1") {
        // if(this.IDCard.length == 18){
        this.forbid = true;
        // }
        if (
          !/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/.test(
            this.IDCard
          )
        ) {
          Toast.fail("格式错误");
          this.IDCard = "";
          // 622726199710301351 272
          return;
        }
        if (this.IDCard.length == "18") {
          let format = this.IDCard;
          // console.log("身份证" + format);
          let year = format.slice(6, 10);
          let month = format.slice(10, 12);
          let day = format.slice(12, 14);
          let set = format.slice(16, 17);
          if (set % 2 == 0) {
            this.set = 1;
          } else {
            this.set = 0;
          }
          // console.log(`${month}---${day}`);
          year = Number(year);
          month = Number(month);
          if (month < 10) {
            month = `0${month}`;
            // console.log(typeof Number(month));
            // console.log(month - 1);
          }
          // console.log(typeof ccc);
          let MyDate = new Date();
          // console.log(MyDate);
          let annual = MyDate.getFullYear(); //获取完整的年份(4位,1970-????)
          let luna = MyDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
          // 将用户输入的年份和月份转成数字类型
          annual = Number(annual);
          luna = Number(luna);
          // 年份相减，获取年龄的大小
          let age = annual - year;
          // console.log("age:" + age);
          // 月份相减，判断年龄是否减1
          let minus = luna - month;
          // console.log("minus" + minus);
          if (minus < 0) {
            age = age - 1;
          }
          // console.log(age);
          // console.log(this.override);
          if (this.override == "") {
            Toast("请选择车型");
            this.IDCard = "";
            this.set = "";
            return;
          }
          // 判断类型

          if (
            this.override == "C1" ||
            this.override == "C2" ||
            this.override == "C3" ||
            this.override == "C4" ||
            this.override == "C5" ||
            this.override == "D" ||
            this.override == "E" ||
            this.override == "F" ||
            this.override == "M"
          ) {
            if (age >= 18) {
              this.years = `${year}-${month}-${day}`;
            } else {
              this.inconformity();
            }
          }

          if (
            this.override == "A3" ||
            this.override == "B2" ||
            this.override == "D" ||
            this.override == "N" ||
            this.override == "P"
          ) {
            if (age >= 20) {
              this.years = `${year}-${month}-${day}`;
            } else {
              this.inconformity();
            }
          }

          if (this.override == "B1") {
            if (age >= 21) {
              this.years = `${year}-${month}-${day}`;
            } else {
              this.inconformity();
            }
          }

          if (this.override == "A2") {
            if (age >= 24) {
              this.years = `${year}-${month}-${day}`;
            } else {
              this.inconformity();
            }
          }

          if (this.override == "A1") {
            if (age >= 26) {
              this.years = `${year}-${month}-${day}`;
            } else {
              this.inconformity();
            }
          }

          if (
            this.override == "C1" ||
            this.override == "C2" ||
            this.override == "C5" ||
            // this.override == "D" ||
            // this.override == "E" ||
            this.override == "F"
            // this.override == "M"
          ) {
            if (age <= 70) {
              this.years = `${year}-${month}-${day}`;
            } else {
              Toast.fail("您已超龄，不能申请驾驶资格");
              this.IDCard = "";
              this.set = "";
              this.years = "";
            }
          }

          if (
            this.override == "C1" ||
            this.override == "D" ||
            this.override == "M"
          ) {
            if (age <= 60) {
              this.years = `${year}-${month}-${day}`;
            } else {
              Toast.fail("您已超龄，不能申请驾驶资格");
              this.IDCard = "";
              this.set = "";
              this.years = "";
            }
          }
          if (
            this.override == "A1" ||
            this.override == "A2" ||
            this.override == "A3" ||
            this.override == "B1" ||
            this.override == "B2" ||
            this.override == "N" ||
            this.override == "P"
          ) {
            if (age <= 50) {
              this.years = `${year}-${month}-${day}`;
            } else {
              Toast.fail("您已超龄，不能申请驾驶资格");
              this.IDCard = "";
              this.set = "";
              this.years = "";
            }
          }
        }

        // 当用户身份证是十五位的时候验证的方法
        // if (this.IDCard.length == "15") {
        //   let format = this.IDCard;
        //   // console.log("身份证" + format);
        //   let year = format.slice(6, 8);
        //   let month = format.slice(8, 10);
        //   let day = format.slice(10, 12);
        //   let set = format.slice(15, 16);
        //   if (set % 2 == 0) {
        //     this.set = 1;
        //   } else {
        //     this.set = 0;
        //   }
        //   year = Number(year);
        //   month = Number(month);
        //   // console.log(typeof ccc);
        //   let MyDate = new Date();
        //   // console.log(MyDate);
        //   let annual = MyDate.getFullYear(); //获取完整的年份(4位,1970-????)
        //   let luna = MyDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
        //   // 将用户输入的年份和月份转成数字类型
        //   annual = Number(annual);
        //   luna = Number(luna);
        //   // 年份相减，获取年龄的大小
        //   let age = annual - year;
        //   console.log("age:" + age);
        //   // 月份相减，判断年龄是否减1
        //   let minus = luna - month;
        //   console.log("minus" + minus);
        //   if (minus < 0) {
        //     age = age - 1;
        //   }
        //   console.log(age);
        //   console.log(this.override);
        //   if (this.override == "") {
        //     Toast("请选择车型");
        //     this.IDCard = "";
        //     this.set = "";
        //     return;
        //   }
        //   // 判断类型

        //   if (
        //     this.override == "C1" ||
        //     this.override == "C2" ||
        //     this.override == "C3" ||
        //     this.override == "C5" ||
        //     this.override == "D" ||
        //     this.override == "E" ||
        //     this.override == "F" ||
        //     this.override == "M"
        //   ) {
        //     if (age >= 18) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       this.inconformity();
        //     }
        //   }

        //   if (
        //     this.override == "A3" ||
        //     this.override == "B2" ||
        //     this.override == "D"
        //   ) {
        //     if (age >= 20) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       this.inconformity();
        //     }
        //   }

        //   if (this.override == "B1") {
        //     if (age >= 21) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       this.inconformity();
        //     }
        //   }

        //   if (this.override == "A2") {
        //     if (age >= 24) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       this.inconformity();
        //     }
        //   }

        //   if (this.override == "A1") {
        //     if (age >= 26) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       this.inconformity();
        //     }
        //   }

        //   if (
        //     this.override == "C1" ||
        //     this.override == "C2" ||
        //     this.override == "C5" ||
        //     this.override == "D" ||
        //     this.override == "E" ||
        //     this.override == "F" ||
        //     this.override == "M"
        //   ) {
        //     if (age <= 70) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       Toast.fail("您已超龄，不能申请驾驶资格");
        //       this.IDCard = "";
        //       this.set = "";
        //       this.years = "";
        //     }
        //   }

        //   if (
        //     this.override == "C1" ||
        //     this.override == "D" ||
        //     this.override == "M"
        //   ) {
        //     if (age <= 60) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       Toast.fail("您已超龄，不能申请驾驶资格");
        //       this.IDCard = "";
        //       this.set = "";
        //       this.years = "";
        //     }
        //   }
        //   if (
        //     this.override == "A3" ||
        //     this.override == "A1" ||
        //     this.override == "D"
        //   ) {
        //     if (age <= 50) {
        //       this.years = `${year}-${month}-${day}`;
        //     } else {
        //       Toast.fail("您已超龄，不能申请驾驶资格");
        //       this.IDCard = "";
        //       this.set = "";
        //       this.years = "";
        //     }
        //   }
        // }

        // console.log("身份证年" + year, month);

        // 最后判断年龄是否在这个区间
        // if (age >= 18 && age <= 60) {
        //   this.years = `${year}-${month}-${day}`;
        // } else {
        //   Toast.fail("年龄不符合");
        // }
      } else if (this.papersType == "2") {
        this.forbid = false;
        console.log("护照");
      } else if (this.papersType == "3") {
        this.forbid = false;
        console.log("港澳台身份证");
      } else if (this.papersType == "4") {
        this.forbid = false;
        console.log("军官证");
      }
    },

    // 居住证签发时间
    cardSigner() {
      this.signer = true;
    },

    // 暂住证
    uptown() {
      this.residentialTome = true;
    },

    // 当身份证不符合驾驶年龄时执行的操作
    inconformity() {
      Toast.fail("您尚未到达申报年龄，暂不能申请驾驶资格");
      this.IDCard = "";
      this.set = "";
      this.years = "";
    },

    // registerFor() {
    //   this.signUp = false;
    // },

    // applyTime() {
    //   this.signUp = true;
    // },

    // 出生选择的显示
    showData() {
      this.show = true;
    },

    // 暂住证到期时间
    temporaryTime() {
      this.residentialTome = false;
      var myDate = this.dataccc;
      let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
      let month = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
      let day = myDate.getDate(); //获取当前日(1-31)
      if (month < 10) {
        month = `0${month}`;
      }
      if (day < 10) {
        day = `0${day}`;
      }
      this.stayExpire = `${year}-${month}-${day}`;
    },
    temporary() {
      this.residentialTome = false;
    },

    papers() {
      // 判断当前用户选择了那种证件，进行相应的验证
      // 1：身份证，2：护照，3：港澳台身份证，4：军官证...
      if (this.papersType == "1") {
        this.forbid = true;
      } else if (this.papersType == "2") {
        this.forbid = false;
      } else if (this.papersType == "3") {
        this.forbid = false;
      } else {
        this.forbid = false;
      }
    },

    // 是否同意协议
    IfConsent() {
      if (this.condition) {
        this.condition = false;
      } else {
        this.condition = true;
      }
    },

    // 居住证签发时间
    residenceTime() {
      this.signer = false;
      var myDate = this.issuingAuthority;
      let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
      let month = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
      let day = myDate.getDate(); //获取当前日(1-31)
      if (month < 10) {
        month = `0${month}`;
      }
      if (day < 10) {
        day = `0${day}`;
      }
      this.cardTime = `${year}-${month}-${day}`;
    },
    residence() {
      this.signer = false;
      // issuingAuthority
    },

    // 日期选择确认的时候关闭弹窗
    CallOff() {
      this.show = false;
    },
    ascertain() {
      this.show = false;
      var myDate = this.currentDate;
      let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
      let month = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
      let day = myDate.getDate(); //获取当前日(1-31)
      if (month < 10) {
        month = `0${month}`;
      }
      if (day < 10) {
        day = `0${day}`;
      }
      this.years = `${year}-${month}-${day}`;
      // console.log(`year${year},month:${month - 1},day:${day}`);
      // this.currentDate =
    },
    contrsct() {
      this.$router.push({ path: "/Contract" });
    }
  },
  components: {
    [Dialog.Component.name]: Dialog.Component
  }
};
</script>

<style></style>
